﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SPPD.controller;
using SPPD.model;


namespace SPPD
{
    /// <summary>
    /// Interaction logic for Window2.xaml
    /// </summary>
    public partial class Window2 : Window
    {
        public List<sppd> list_sppd = new List<sppd>();
        public int select;
        public sppd edit = new sppd();
        public pegawai pegawaiLogin = new pegawai();
        public Window2(pegawai pgawai)
        {
            InitializeComponent();
            pegawaiLogin = pgawai;
        }

        private void button1_Copy_Click(object sender, RoutedEventArgs e)
        {
            MainWindow main = new MainWindow();
            this.Hide(); main.Show();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            Window5 tolak = new Window5(1,edit,pegawaiLogin);
            this.Hide(); tolak.Show();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string id;
            id = list_sppd[select].id_sppd;
            controller_sppd dummy = new controller_sppd();
            dummy.update(edit);
        }

        

        private void button2_Copy_Click(object sender, RoutedEventArgs e)
        {
            controller_sppd dummy = new controller_sppd();

            list_sppd = dummy.load();
            for (int i = 0; i < list_sppd.Count; i++)
            {
                if (list_sppd[i].status < 3)
                {
                    list_sppd.RemoveAt(i);
                }
            }
            data.ItemsSource = list_sppd;
        }

        private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            select = data.SelectedIndex;
            edit = list_sppd[select];
            pegawai dummy = edit.ketua;
            textBoxBagian.Text = dummy.bagian.ToString();
            textBoxBerangkat.Text = edit.tanggal_perjalanan.ToString();
            textBoxKepentingan.Text = edit.kepentingan.ToString();
            textBoxNama.Text = dummy.nama;
            if (edit.status < 3) textBoxStatus.Text = "Belum disetujui";
            else textBoxStatus.Text = "Sudah disetujui";
            textBoxTanggal.Text = edit.tanggal_pengajuan.ToString();
            textBoxTujuan.Text = edit.tujuan.ToString();
            select = data.SelectedIndex;
            edit = list_sppd[select]; 
            
           
        }
    }
}
